Repository: https://github.com/jupyter-widgets/ipyleaflet

Installation:

conda install -c conda-forge ipyleaflet

Base map


In [ ]:
from ipyleaflet import Map, basemaps, basemap_to_tiles

In [ ]:
center = (52.204793, 360.121558)

m = Map(
    layers=(basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2018-11-12"), ),
    center=center,
    zoom=4
)

m

Layers

Marker


In [ ]:
from ipyleaflet import Marker, Icon

icon = Icon(icon_url='https://leafletjs.com/examples/custom-icons/leaf-red.png', icon_size=[38, 95], icon_anchor=[22,94])
mark = Marker(location=center, icon=icon, rotation_origin='22px 94px')

m.add_layer(mark)

In [ ]:
import time

for _ in range(40):
    mark.rotation_angle += 15
    time.sleep(0.1)

Heatmap layer


In [ ]:
from ipywidgets import Button, IntSlider, link
from ipyleaflet import Heatmap
from random import gauss
import time

In [ ]:
center = (37.09, -103.66)
zoom = 5

In [ ]:
def create_random_data(length):
    "Return a list of some random lat/lon/value triples."
    return [[gauss(center[0], 2), 
             gauss(center[1], 4),
             gauss(700, 300)] for i in range(length)]

In [ ]:
m.center = center
m.zoom = zoom

In [ ]:
heat = Heatmap(locations=create_random_data(1000), radius=20, blur=10)
m.add_layer(heat)

In [ ]:
def generate(_):
    heat.locations = create_random_data(1000)

button = Button(description='Generate data', button_style='success')
button.on_click(generate)
button

In [ ]:
m

In [ ]:
slider = IntSlider(min=10, max=30, value=heat.radius)
link((slider, 'value'), (heat, 'radius'))
slider

Velocity


In [ ]:
from ipyleaflet import Velocity
import xarray as xr

In [ ]:
center = (0, 0)
zoom = 4

m2 = Map(center=center, zoom=zoom, interpolation='nearest', basemap=basemaps.CartoDB.DarkMatter)
m2

In [ ]:
ds = xr.open_dataset('src/wind-global.nc')
display_options = {
    'velocityType': 'Global Wind',
    'displayPosition': 'bottomleft',
    'displayEmptyString': 'No wind data'
}
wind = Velocity(data=ds,
                zonal_speed='u_wind',
                meridional_speed='v_wind',
                latitude_dimension='lat',
                longitude_dimension='lon',
                velocity_scale=0.01,
                max_velocity=20,
                display_options=display_options)
m2.add_layer(wind)

Controls


In [ ]:
from ipyleaflet import Map, basemaps, basemap_to_tiles, SplitMapControl

m = Map(center=(42.6824, 365.581), zoom=5)

right_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-11-11")
left_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisAquaBands721CR, "2017-11-11")

control = SplitMapControl(left_layer=left_layer, right_layer=right_layer)
m.add_control(control)

m

Clean


In [ ]:
from ipywidgets import Widget
Widget.close_all()

Example: ipyleaflet application using qgrid and bqplot